#ifndef BASE_AUDIO_H_
#define BASE_AUDIO_H_

#include "../sleipner_config.h"
#include "num/named_set.h"
#include <string>
namespace LuaPlus
{
    class LuaState;
}   // namespace LuaPlus

namespace vfs
{
	struct LoadedBlock;
}	
namespace audio
{

typedef int				AudioHandle;
typedef unsigned int	AudioFile;

class AudioSet;

struct	Sample
{
	unsigned int	SampleRate;
	unsigned int	Size;
    intptr_t		pData;
	AudioFile		Handle;
	std::string		File;
};

struct	MusicSegments
{
	std::string		Name;
	std::string		MusicFile;
	int				Order;
	int				Row;
	float			Bias;
};


// temp audio-engine
class Audio
{
public:

	virtual void			Init(const std::string& AudioSet);
			void			LoadAudioSet(const std::string& AudioSet);
	virtual void			Shutdown() = 0; 
	
	virtual AudioFile		LoadSound(const std::string& Name, bool Repeat = false);	// just channels through to LoadSoundFromMemory
	virtual void			StopAll() ;		// just stops music.. let the rest die out naturally

	virtual AudioHandle		PlayMusic(const std::string& Name, float AudioBias = 1.0f, bool Repeat = true)= 0;
	virtual AudioHandle		PlayMusicH(AudioFile, float AudioBias = 1.0f) = 0;
	virtual AudioHandle		PlayEvent(const std::string& Name, float AudioBias = 0);
	virtual AudioFile		LoadSoundFromMemory(vfs::LoadedBlock& Data, bool Repeat = false) = 0;
	virtual AudioHandle		PlaySFX(AudioFile	ID , float AudioBias) = 0;

	virtual bool			IsPlaying(AudioHandle Handle) = 0;
	virtual void			StopSound(AudioHandle Handle) = 0;
	virtual void			StopMusic() = 0;
	virtual void			PauseAll() = 0;
	virtual void			RestartAll() = 0;
	virtual unsigned int	GetFileSize(AudioHandle	Handle) = 0;

	virtual void	SetSFXVolume(int	Volume) { m_SFXVolume = Volume; };
	virtual void	SetMusicVolume(int	Volume) { m_MusicVolume = Volume; };

	void			PlaySegment(const std::string& Name);

	int				GetSFXVolume() const { return m_SFXVolume; };
	int				GetMusicVolume() const { return m_MusicVolume; };
	bool			IsInit() const { return m_IsInit; }

	virtual			~Audio();
    static void      Register(LuaPlus::LuaState* _pScript);

	void			GetAudioInfo(unsigned int& Files, unsigned int& Memory);
protected:

					Audio();
	AudioHandle		m_CurrentMusic;
	AudioSet*		m_pAudioSet;
	int				m_SFXVolume;
	int				m_MusicVolume;
	std::string		m_MusicFile;
	float			m_AudioBias;
	float			m_MusicBias;

	num::NamedSet<Sample*>			m_Samples;
	num::NamedSet<MusicSegments*>	m_Segments;
	
	struct			BrokenSamples
	{
		std::string		Name;
	};
	num::NamedSet<BrokenSamples*>	m_Broken;

	std::string		m_CurrentSegment;

	void			LoadSegments(const std::string& File);
	bool			m_IsInit;
};

}  //namespace audio

#endif // BASE_AUDIO_H_
